package cn.hf.mychat.teach.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.DelegatingFilterProxy;

import javax.servlet.DispatcherType;

//测试
//@ServletComponentScan
//@SpringBootApplication
//@ImportResource(value = "classpath:spring-*.xml")
//@ComponentScan({"cn.hf.mychat.teach.dao"})
public class ApplicationService extends SpringBootServletInitializer {
    /*public static void main(String[] args) {
        SpringApplication.run(ApplicationService.class);
    }*/


   /*
   字符串拦截
    */
   @Bean
   public FilterRegistrationBean ServletEncodingFilterRegistration(){

       FilterRegistrationBean registrationBean=  new FilterRegistrationBean(new CharacterEncodingFilter());
       registrationBean.addUrlPatterns("/*");
       registrationBean.addInitParameter("encoding","UTF-8");
       registrationBean.addInitParameter("forceEncoding","true");
       registrationBean.setName("encodingFilter");
       registrationBean.setOrder(3);
       return registrationBean;
   }
    /*
    安全认证拦截
     */
    @Bean
    public FilterRegistrationBean ServletDelegatingFilterProxyRegistration(){

        FilterRegistrationBean registrationBean=  new FilterRegistrationBean(new DelegatingFilterProxy());
        registrationBean.addUrlPatterns("/*");
        registrationBean.setName("springSecurityFilterChain");
        registrationBean.setDispatcherTypes(DispatcherType.REQUEST,DispatcherType.FORWARD);
        registrationBean.setOrder(4);
        return registrationBean;
    }
   /* *//*
    AES加密拦截
     *//*
     @Bean
    public FilterRegistrationBean ServletEncryptionFilterRegistration(){

        FilterRegistrationBean registrationBean=  new FilterRegistrationBean(new EncryptionFilter());
        registrationBean.addUrlPatterns("/*");
        registrationBean.setName("encryptionFilter");
        registrationBean.setOrder(5);
        return registrationBean;
    }*/

    /*
 安全认证拦截
  */
   /* @Bean
    public FilterRegistrationBean ServletInterfaceFilterRegistration(){

        FilterRegistrationBean registrationBean=  new FilterRegistrationBean(new InterfaceFilter());
        registrationBean.addUrlPatterns("/*");
        registrationBean.setName("interfaceFilter");
        registrationBean.setOrder(5);
        return registrationBean;
    }*/


}
